package com.sugon.controller.device;

import com.alibaba.fastjson.JSON;
import com.sugon.annotation.AutoLog;
import com.sugon.entity.DevMoldRuntimeRecordEntity;
import com.sugon.service.DevMoldRuntimeRecordService;
import com.sugon.utils.PageUtils;
import com.sugon.utils.Query;
import com.sugon.utils.R;
import org.apache.shiro.authz.annotation.RequiresPermissions;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;
import java.util.Map;

/**
 * 设备-模具运行记录，用来记录某台设备用模具运行了多长时间Controller
 *
 * @author YuXD
 * @date 2022-05-10 10:19:33
 */

@RestController
@RequestMapping("devMold/stat")
public class DevMoldRuntimeAnalyseController {
    @Autowired
    private DevMoldRuntimeRecordService devMoldRuntimeRecordService;

    /**
     * 设备PM工单数量分布统计
     * 首页用
     */
    /**
     * 统计设备-模具故障市场列表
     *
     * @param param 统计参数
     * @return
     */
    @RequestMapping("/statDevMoldFaultDuration")
    public R statDevMoldFaultDuration(@RequestBody Map<String, Object> param) {
        return R.ok().put("statResult",null);
    }

    /**
     * 统计设备-模具：正常和故障时长分布
     *
     * @param param 统计参数
     * @return
     */
    @RequestMapping("/statDevMoldDurationDistribution")
    public R statDevMoldDurationDistribution(@RequestBody Map<String, Object> param) {
        String jsonStr = "{\"parkingApron\":{\"dimensions\":[\"Name\",\"Type\",\"Near Bridge\"],\"data\":[[\"AB94\",\"W\",true],[\"AB95\",\"W\",true],[\"AB96\",\"W\",true],[\"AB97\",\"W\",true],[\"AB98\",\"W\",true],[\"AS3\",\"W\",true],[\"AS4\",\"W\",true],[\"AS5\",\"W\",true],[\"AS6\",\"W\",true],[\"AS7\",\"W\",true],[\"AS8\",\"W\",true]]},\"flight\":{\"dimensions\":[\"Parking Apron Index\",\"Arrival Time\",\"Departure Time\",\"Flight Number\",\"VIP\",\"Arrival Company\",\"Departure Company\",\"Arrival Line\",\"Departure Line\",\"Report Time\"],\"data\":[[43,1496840400000,1496934000000,\"M766OG\",true,\"QW\",\"QW\",\"XGF-HAC\",\"HAC-CFA\",1495360800000],[317,1496840400000,1496934000000,\"Y3683\",true,\"AS\",\"AS\",\"MGT-HAC\",\"HAC-YPP\",1496830500000],[113,1496840400000,1496934000000,\"Y3064\",true,\"AS\",\"AS\",\"KMS-HAC\",\"HAC-YPP\",1496123400000],[79,1496840400000,1496934000000,\"Y4686\",true,\"WA\",\"WA\",\"RMX-DWH-HAC\",\"HAC-XTL\",1496744100000]]}}";
        return R.ok().put("rawData", JSON.parse(jsonStr));
    }

    /**
     * 查看列表
     */
    @RequestMapping("/list")
    @RequiresPermissions("devmoldruntimerecord:list")
    @ResponseBody
    public R list(@RequestParam Map<String, Object> params) {
        //查询列表数据
        Query query = new Query(params);

        List<DevMoldRuntimeRecordEntity> devMoldRuntimeRecordList = devMoldRuntimeRecordService.queryList(query);
        int total = devMoldRuntimeRecordService.queryTotal(query);

        PageUtils pageUtil = new PageUtils(devMoldRuntimeRecordList, total, query.getLimit(), query.getPage());

        return R.ok().put("page", pageUtil);
    }

    /**
     * 查看信息
     */
    @RequestMapping("/info/{id}")
    @RequiresPermissions("devmoldruntimerecord:info")
    @ResponseBody
    public R info(@PathVariable("id") String id) {
        DevMoldRuntimeRecordEntity devMoldRuntimeRecord = devMoldRuntimeRecordService.queryObject(id);

        return R.ok().put("devMoldRuntimeRecord", devMoldRuntimeRecord);
    }

    /**
     * 保存
     */
    @AutoLog("设备-模具运行记录，用来记录某台设备用模具运行了多长时间--保存")
    @RequestMapping("/save")
    @RequiresPermissions("devmoldruntimerecord:save")
    @ResponseBody
    public R save(@RequestBody DevMoldRuntimeRecordEntity devMoldRuntimeRecord) {
        devMoldRuntimeRecordService.save(devMoldRuntimeRecord);

        return R.ok();
    }

    /**
     * 修改
     */
    @AutoLog("设备-模具运行记录，用来记录某台设备用模具运行了多长时间--修改")
    @RequestMapping("/update")
    @RequiresPermissions("devmoldruntimerecord:update")
    @ResponseBody
    public R update(@RequestBody DevMoldRuntimeRecordEntity devMoldRuntimeRecord) {
        devMoldRuntimeRecordService.update(devMoldRuntimeRecord);

        return R.ok();
    }

    /**
     * 删除
     */
    @AutoLog("设备-模具运行记录，用来记录某台设备用模具运行了多长时间--删除")
    @RequestMapping("/delete")
    @RequiresPermissions("devmoldruntimerecord:delete")
    @ResponseBody
    public R delete(@RequestBody String[] ids) {
        devMoldRuntimeRecordService.deleteBatch(ids);

        return R.ok();
    }

    /**
     * 查看所有列表
     */
    @RequestMapping("/queryAll")
    @ResponseBody
    public R queryAll(@RequestParam Map<String, Object> params) {

        List<DevMoldRuntimeRecordEntity> list = devMoldRuntimeRecordService.queryList(params);

        return R.ok().put("list", list);
    }
}
